package com.itheimaoa.service.process.impl;

import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.itheimaoa.domain.process.Test;
import com.itheimaoa.service.base.impl.CommonServiceImpl;
import com.itheimaoa.service.process.ITestService;

@Service
@Transactional
public class TestServiceImpl extends CommonServiceImpl<Test> implements ITestService {
	@Override
	@Transactional(readOnly = true)
	public Test findApplyId(String applyId) {
		String jpql = " from Test o where o.apply.aid = ? order by o.uptime desc";
		List<Test> tests = this.hibernateTemplate.find(jpql, applyId);
		if (tests != null && tests.size() > 0) {
			tests.get(0);
		}
		return null;
	}

	@Override
	@Transactional(readOnly = true)
	public Test findTestByApplyId(String applyId) {
		String jpql = " from Test o where o.apply.aid = ?";
		List<Test> tests = this.hibernateTemplate.find(jpql, applyId);
		if (tests != null && tests.size() > 0) {
			for (Test t : tests) {
				if (!t.getAgree()) {
					return t;
				}
			}
		}
		return null;
	}

	@Override
	@Transactional(readOnly = true)
	public List<Test> findTestsByApplyId(String applyId) {
		String jpql = " from Test o where o.apply.aid = ? order by o.uptime asc";
		List<Test> tests = this.hibernateTemplate.find(jpql, applyId);
		return tests;
	}

}
